﻿using UnityEngine;
using UnityEngine.UI;

public class SettingsController : MonoBehaviour
{
    public GameObject ShowBox;
    public GameObject ConfirmationBox;
    public GameObject UpdateShowBox;

    private void Start()
    {
        ConfirmationBox.SetActive(false);
        ShowBox.SetActive(false);
        UpdateShowBox.SetActive(false);
    }

    public void ClearPlayerConfig()
    {
        ConfirmationBox.SetActive(true);
    }
    public void ConfirmClearPlayerConfig()
    {
        ConfigManager.ClearRecords();
        ConfirmationBox.SetActive(false);
        ShowBox.SetActive(true);
    }
    public void CancelClearPlayerConfig() { ConfirmationBox.SetActive(false); }
    public void CloseShowBox() { ShowBox.SetActive(false); UpdateShowBox.SetActive(false); }

    public void UpdateRound()
    {
        if (TCPClient.ClientSocket.Connected)
        {
            UpdateShowBox.GetComponentInChildren<Text>().text = TCPClient.Error.ToString();
            if (TCPClient.Error == System.Net.Sockets.SocketError.Success)
                UpdateShowBox.GetComponentInChildren<Text>().text = "更新成功";
            // UpdateShowBox.GetComponentInChildren<Text>().text = "更新成功";
            UpdateShowBox.SetActive(true);
            TCPClient.Request = new Request(ConfigManager.LoadSettings().Username, Request.GET_ROUND_REQUEST);
            TCPClient.SendRequest();
        }
        else
        {
            UpdateShowBox.GetComponentInChildren<Text>().text = "无法连接服务器";
            UpdateShowBox.SetActive(true);
        }
    }
}
